<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>Sign in &laquo; Admin</title>
  <link rel="stylesheet" href="../static/assets/vendors/bootstrap/css/bootstrap.css">
  <link rel="stylesheet" href="../static/assets/css/admin.css">
</head>
<body>
  <div class="login">
    <form class="login-wrap">
      <img class="avatar" src="../static/assets/img/default.png">
      <!-- 有错误信息时展示 -->
      <!-- <div class="alert alert-danger">
        <strong>错误！</strong> 用户名或密码错误！
      </div> -->
      <div class="alert alert-danger" style="display: none;">
  <strong>错误！</strong><span id="msg">用户名或密码错误！</span>
</div>
      <div class="form-group">
        <label for="email" class="sr-only">邮箱</label>
        <input id="email" type="email" class="form-control" placeholder="邮箱" autofocus>
      </div>
      <div class="form-group">
        <label for="password" class="sr-only">密码</label>
        <input id="password" type="password" class="form-control" placeholder="密码">
      </div>
       <!--  将a连接改为span标签，这样就不用在事件中阻止跳转 -->
      <span id="btn-login" class="btn btn-primary btn-block" >登 录</span>
    </form>
  </div>
 <script src="../static/assets/vendors/jquery/jquery.js"></script>
 <script>
 $(function(){
    //给登录按钮注册点击事件
    $("#btn-login").on("click",function(){
     //点击事件处理程序中的代码
     //1.收集用户的邮箱和密码
     var email = $("#email").val();
     var password = $("#password").val();
     //2.先给前端把数据做一下简单的验证
       //2.1验证邮箱是否正确
       var reg = /^\w+[@]\w+[.]\w+$/;
       if (!reg.test(email)) {
          //提示用户输入有误
          $("#msg").text("您输入的邮箱有误，请爸爸重新输入谢谢！");
          //显示错误区域
          $(".alert").show();
          return;
       }
    $.ajax({
        type:"POST",
        data:{email:email,password:password},
        url:"api/_userLogin.php",
        success:function(res){
          //4.判断返回的结果是否登录成功
          if (res.code ==1) {
           //跳转到后台主页面
           location.href ="index.php";
         }else{
          $("#msg").text("大爷你的密码或者用户名错了");
          $(".alert").show();
         }

          }
      
    })

    })

   })




 </script>
</body>
</html>
